/*
 * RTSAI - Real-Time Strategy engine for AI research
 * Copyright(C) 2006 DIMAp-UFRN, licensed under LGPL
 *
 * GameObject definitions
 */

#ifndef GAMEOBJECT_H
#define GAMEOBJECT_H

#include "AbstractVehicle.h"
#include "Obstacle.h"
#include "Unit.h"
#include "Common.h"

/*! This class implements an abstract GameObject that will be used to create
 *  several objects of the game.
 */
class GameObject : public OpenSteer::Obstacle
{
    public:
        GameObject () : type ( "NoType" ),
                        _seenFrom ( outside ),
                        obstacle ( false ) { /* Empty */ };
       
       
        GameObject ( string t ) : type(t),
                                  _seenFrom ( outside ),
                                  obstacle ( false ) { /* Empty */ };
       
       
        virtual ~GameObject() { /* Empty */ };


        // From OpenSteer::Obstacle
        seenFromState seenFrom () const
        {
            return _seenFrom;
        }
      

        void setSeenFrom (seenFromState s)
        {
            _seenFrom = s;
        }

       
        string get_type() const
        {
            return type;
        }
      
      
        Vector3D position() const
        {
            return pos;
        }

        virtual Vector3D steerToAvoid (const OpenSteer::AbstractVehicle& v, const float minTimeToCollision) const = 0;
        virtual bool collideWithSphere ( const Vector3D &c, float r ) const = 0;

    protected:
        /// enum type (From OpenSteer::Obstacle)
        seenFromState _seenFrom;
        /// boolean that indicates if this object is an obstacle
        bool obstacle;
        /// type name set in the game configuration
        string type;
        /// Object position
        Vector3D pos;
};


/*! This class implements a spherical object by a inheritance from a
 *  GameObject
 */
class SphObject : public GameObject
{
    public:
        // constructors
        SphObject (string t, float r, Vector3D c, bool o) : GameObject(t),
                                                            radius(r),
                                                            center (c)
        {
                obstacle = o; pos = c;
        }


        SphObject (string t) : GameObject(t), radius(1), center (Vector3D::zero)
        {
            obstacle = false; pos = center;
        }

        Vector3D steerToAvoid (const OpenSteer::AbstractVehicle& v,
                               const float minTimeToCollision) const;
        virtual bool collideWithSphere ( const Vector3D &c, float r ) const;

    public:
        /// Radius of the spherical object
        float radius;
        /// Center of the spherical object
        Vector3D center;
};


/*! This class implements a rectangle object by a inheritance from a
 *  GameObject
 */
class RectObject : public GameObject
{
    public:
        // constructors
        RectObject (float w, float h, Vector3D c, bool o) : width(w),
                                                            height(h),
                                                            topleft (c)
        {
            obstacle = o;
        }

       
        RectObject () : width(1), height(1), topleft (Vector3D::zero)
        {
            obstacle = false;
        }

        Vector3D steerToAvoid (const OpenSteer::AbstractVehicle& v,
                               const float minTimeToCollision) const;
        virtual bool collideWithSphere ( const Vector3D &c, float r ) const;

    public:
        /// Rectangle dimensions
        float width, height;
        /// The top left corner of the rectangle
        Vector3D topleft;
};


#endif // GAMEOBJECT_H
